/**
 * 
 * Klasse zum Sortieren der Datens�tze
 * 
 */

package com.example.RemindMe;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Comparator;
import java.util.Date;

public class SortByDate implements Comparator
{
	
	final SimpleDateFormat df = new SimpleDateFormat("dd.MM.yyyy HH:mm");
	
	
	public int compare(Object object1, Object object2)
	{
		int value=0;
 
		AlarmItem emp1 = (AlarmItem) object1;
		AlarmItem emp2 = (AlarmItem) object2;
		Date dateEmp1 = null;
		Date dateEmp2 = null;
		
		
		try {
			dateEmp1 = df.parse(emp1.getTime());
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		try {
			dateEmp2 = df.parse(emp2.getTime());
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		System.out.println(dateEmp1.compareTo(dateEmp2));
 
		if(dateEmp1.compareTo(dateEmp2) == -1)
			value = 1;
		else if(dateEmp1.compareTo(dateEmp2) == 1)
			value = -1;
		else if(dateEmp1.compareTo(dateEmp2) == 0)
			value = 0;
 
		return value;
	}
}
